package com.bdqn.systems.service.impl;

import com.bdqn.exception.BusinessException;
import com.bdqn.response.ResultCode;
import com.bdqn.systems.entity.Department;
import com.bdqn.systems.mapper.DepartmentMapper;
import com.bdqn.systems.service.DepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cp
 * @since 2020-11-30
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {

    @Override
    public List<Department> findDeptAndCount() {
        List<Department> deptAndCount = this.baseMapper.findDeptAndCount();
        // 判断部门是否存在
        if(deptAndCount.size()==0){
            throw new BusinessException(ResultCode.DEPARTMENT_NOT_EXIST.getCode(),
                    ResultCode.DEPARTMENT_NOT_EXIST.getMessage());
        }
        return deptAndCount;
    }
}
